package com.wkbb.sports.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wkbb.common.base.BaseController;
import com.wkbb.common.constants.ErrorCode;
import com.wkbb.common.constants.VersionConstant;
import com.wkbb.common.dto.ResultDTO;
import com.wkbb.common.dto.basic.UserDto;
import com.wkbb.sports.dto.TagDto;
import com.wkbb.sports.model.HlifeTag;
import com.wkbb.sports.model.HlifeTeachPlan;
import com.wkbb.sports.service.TagService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

@RestController
@Api(description = "标签管理")
@RequestMapping("/sports/{apiVersion}/tag")
@Slf4j
public class TagController extends BaseController{
	
	@Autowired
	private TagService tagService;
	
	
	@ApiOperation(value = "查询标签")
	@RequestMapping(value = "/selTagList", method = RequestMethod.GET)
	public ResultDTO<?> selTagList(
			@ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
		    @ApiParam(value = "名称", required = false) @RequestParam(name = "tagName", required = false)  String tagName,
		    @ApiParam(value = "类型", required = false) @RequestParam(name = "tagType", required = false)  String tagType){
		UserDto userDto = this.getUserByLogin();
		if(null == userDto) {
			return new ResultDTO<>(ErrorCode.SECURITY_ACCESS_TOKEN_NOT_EXIST);
		}
		
		Map<String,Object>  map  = new HashMap<>();
		
		List<HlifeTag> tagDto;
		try{
			map.put("tagName", tagName);
			map.put("tagType", tagType==null?1:tagType);
			
			tagDto =tagService.getListByMapParams(map);
			
		}catch(Throwable e) {
			log.error(e.getMessage());
			return new ResultDTO<>(ErrorCode.SYSTEM_ERROR);
		}
		return new ResultDTO<>(tagDto);
	}
	
	

}
